package name.wilbur.course.db.bigone.ui;

import name.wilbur.course.db.bigone.control.RegisterMgr;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class RegisterWin extends BaseWindow {
	private RegisterMgr mgr;
	private Label name_l = null;
	private Label code_l = null;
	private Label password_l = null;
	private Text name_t = null;
	private Text password_t = null;
	private Text code_t = null;
	private Label email_l = null;
	private Text email_t = null;
	private Button sub_b = null;
	private Button reset_b = null;
	
	public RegisterWin() {
		super();
		mgr = new RegisterMgr();
	}
	public RegisterWin(Display disp) {
		super(disp);
		mgr = new RegisterMgr();
	}
	/**
	 * This method initializes sShell
	 */
	public void createSShell() {
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 4;
		GridData data = new GridData(GridData.FILL_HORIZONTAL);
		sShell = new Shell();
		sShell.setText("Register Window");
		sShell.setLayout(gridLayout);
		sShell.setSize(new Point(300, 160));
		name_l = new Label(sShell, SWT.NONE);
		name_l.setText("用户名");
		name_t = new Text(sShell, SWT.BORDER);
		name_t.setLayoutData(data);
		Label filler7 = new Label(sShell, SWT.NONE);
		Label filler13 = new Label(sShell, SWT.NONE);
		password_l = new Label(sShell, SWT.NONE);
		password_l.setText("密码");
		password_t = new Text(sShell, SWT.BORDER);
		password_t.setLayoutData(data);
		password_t.setEchoChar('*');
		Label filler6 = new Label(sShell, SWT.NONE);
		Label filler12 = new Label(sShell, SWT.NONE);
		email_l = new Label(sShell, SWT.NONE);
		email_l.setText("邮件地址");
		email_t = new Text(sShell, SWT.BORDER);
		email_t.setLayoutData(data);
		Label filler5 = new Label(sShell, SWT.NONE);
		Label filler11 = new Label(sShell, SWT.NONE);
		code_l = new Label(sShell, SWT.NONE);
		code_l.setText("注册码");
		code_t = new Text(sShell, SWT.BORDER);
		code_t.setLayoutData(data);
		Label filler4 = new Label(sShell, SWT.NONE);
		Label filler10 = new Label(sShell, SWT.NONE);
		Label filler14 = new Label(sShell, SWT.NONE);
		Label filler15 = new Label(sShell, SWT.NONE);
		sub_b = new Button(sShell, SWT.NONE);
		sub_b.setText("提交");
		sub_b.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				boolean ok = mgr.register(name_t.getText(), password_t.getText(), email_t.getText(), code_t.getText());
				MessageBox warnBox = new MessageBox(sShell, SWT.OK);
				warnBox.setText("注册结果");
				if (!ok) {
					warnBox.setMessage("注册失败");
					warnBox.open();
				} else {
					warnBox.setMessage("注册成功");
					warnBox.open();
					close();
				}
			}
		});
		reset_b = new Button(sShell, SWT.NONE);
		reset_b.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				name_t.setText("");
				password_t.setText("");
				email_t.setText("");
				code_t.setText("");
			}
		});
		reset_b.setText("全部重置");
	}

	public void doAfterDispose() {
		LoginWin lw = new LoginWin(getDisplay());
		lw.open();
	}
}
